import java.io.*;
public class right {
    public static void main (String[] args) throws IOException{
        if (args.length<1) throw new RuntimeException ("not enough arguments");
        if (args.length>1) throw new RuntimeException ("too many arguments");
        BufferedReader reader = new BufferedReader (new FileReader (new File (args[0])));
        String line;
        while ((line = reader.readLine()) != null){
            boolean found = false;
            String[] arguments = line.split(",");
            for (int i = arguments[0].length()-1;i>-1;i--){
                if (arguments[0].charAt(i) == arguments[1].charAt(0)) {
                    System.out.println(i);
                    found = true;
                    break;
                    
                }
            }
            if (!found) System.out.println("-1");
        }
    }
}
